//
//  PublicBlockView.m
//  gaoyipinshangcheng
//
//  Created by jsj on 15/4/24.
//  Copyright (c) 2015年 青岛晨之晖信息服务有限公司. All rights reserved.
//

#import "PublicBlankView.h"
@implementation PublicBlankView
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
-(void)setBackColor:(UIColor *)backColor
{
    _backColor = backColor;
    self.backgroundColor = _backColor;
}
-(void)awakeFromNib
{

}
#pragma mark - 单例 生成view
+(PublicBlankView *)sharedInstanceWithViewController:(UIView *)tmpVC andImage:(NSString*)image andTitle:(NSString*)title andButtonName:(NSString*)name andCGFloat:(CGRect)rect
{
    PublicBlankView *tmpView;
    
    tmpView = [[[NSBundle mainBundle] loadNibNamed:@"PublicBlankView" owner:tmpVC options:nil] objectAtIndex:0];
    tmpView.frame = rect;
    
    [tmpView setBlockViewWithImage:image andTitle:title andButtonName:name andPointY:0];
    
    [tmpVC addSubview:tmpView];
    [tmpVC bringSubviewToFront:tmpView];
    return tmpView;
}

+(PublicBlankView *)sharedLittleInstanceWithViewController:(UIView *)tmpVC andImage:(NSString*)image andTitle:(NSString*)title andButtonName:(NSString*)name andCGFloat:(CGRect)rect andPointY:(CGFloat)y
{
    PublicBlankView *tmpView;
    
    tmpView = [[[NSBundle mainBundle] loadNibNamed:@"PublicBlankView" owner:tmpVC options:nil] objectAtIndex:0];
    tmpView.frame = rect;
    [tmpView setBlockViewWithImage:image andTitle:title andButtonName:name andPointY:y];
    
    [tmpVC addSubview:tmpView];
    [tmpVC bringSubviewToFront:tmpView];
    return tmpView;
    
}
-(void)setBlockViewWithImage:(NSString*)image andTitle:(NSString*)title andButtonName:(NSString*)name andPointY:(CGFloat)y
{
    CGFloat imageH = 125;
    CGFloat imageW = 226;
    CGFloat jianGeH = 30;
    if (y == 0) {
        y = 80;
    }
    
    if (image == nil) {
        _image.image = [UIImage imageNamed:@"prompt_img.png"];
    }else{
    
        _image.image = [UIImage imageNamed:image];
        
    }
    if(title == nil || [title isEqualToString:@""]){
       self.title.hidden = YES;
        self.title.frame = CGRectMake((SCREEN_W-_title.frame.size.width)/2, y, _title.frame.size.width, 0);
    }else{
        self.title.hidden = NO;
       self.title.text = title;
        self.title.font = [UIFont systemFontOfSize:16.0];
        self.title.textColor = ZhongZi_Color;
        [self.title sizeToFit];
        self.title.frame = CGRectMake((SCREEN_W-_title.frame.size.width)/2, y, _title.frame.size.width, 30);
    }
    self.image.frame = CGRectMake((SCREEN_W-imageW)/2,_title.frame.size.height+_title.frame.origin.y+jianGeH, imageW, imageH);
    if(name == nil || [name isEqualToString:@""]){
        self.button.hidden  =YES;
    }else{
        self.button.hidden  =NO;
        [self.button setTitle:name forState:UIControlStateNormal];
        self.button.titleLabel.font = Cell_Medium_Font;
        [self.button.titleLabel sizeToFit];
        [self.button sizeToFit];
        [self.button setTitleColor:RGBColor(255, 66, 89) forState:UIControlStateNormal];
        self.button.frame = CGRectMake((SCREEN_W-_button.frame.size.width)/2, _image.frame.size.height+_image.frame.origin.y+jianGeH, _button.frame.size.width, 30);
    }
    
   
}

- (IBAction)blankButtonFunction:(id)sender
{
    if (_publicBlank) {
        _publicBlank();
    }
}

publicBLankFunctionBlock _publicBlank;
+(void)clickPublicBlankFunction:(publicBLankFunctionBlock)blockBlank
{
    _publicBlank = blockBlank;
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
